var { rptMap } = require('../config/index.js'),
  { wipeOut } = rptMap,
  { san0_close } = require('../common/index.js'),
  { uIsFindColors, uFindColorsClick } = require('../util/index.js');

module.exports = function (count) {
  let isWipeOut = false
  console.show();
  count ? count = count : count = 999;
  let i = 0;  // 刷图次数
  let timeId = 0 // 延迟时间
  if (uIsFindColors([wipeOut.r1, wipeOut.r2, wipeOut.r3], 0)) {
    //!  判断 是不是在刷剿灭
    isWipeOut = true
    log('剿灭模式')
  }
  while (i < count) {
    sleep(1000);
    uFindColorsClick([rptMap.blue]);
    sleep(1000);
    if (san0_close()) break;
    uFindColorsClick([rptMap.red]);
    log('开始第' + (++i) + '次刷图！');
    // * 判断退出
    if (isWipeOut) {  //! 如果是 剿灭模式 的话
      sleep(10 * 60 * 1000)
      while (true) {
        click(1194, 517)
        sleep(10000)
        if (uIsFindColors([wipeOut.r1, wipeOut.r2, wipeOut.r3], 0)) {
          log('第' + i + '次刷图完成!');
          break;
        }
      }
    } else {
      while (true) {
        sleep(2000);
        timeId += 2
        if (timeId % 60 === 0) {
          click(1194, 517);
        }
        if (uIsFindColors([rptMap.end.blue, rptMap.end.orange], 0)) {
          sleep(2000);
          timeId = 0
          click(rptMap.end.blue.x, rptMap.end.blue.y);
          log('第' + i + '次刷图完成!');
          break;
        }
      }
    }
  }
  log('刷图完成，共刷图' + i + '次！');
}

